package com.woniu.service.impl;

import com.woniu.entity.ProcurePlan;
import com.woniu.mapper.ProcurePlanMapper;
import com.woniu.service.ProcurePlanService;
import com.woniu.util.ResponseEnum;
import com.woniu.util.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProcurePlanServiceImpl implements ProcurePlanService {

    @Resource
    private ProcurePlanMapper procurePlanMapper;

    @Override
    public ResponseUtil findAll() {
        List<ProcurePlan> list = procurePlanMapper.findAll();
        return !list.isEmpty()
                ? ResponseUtil.get(ResponseEnum.OK, list)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil findByProcureId(String procureId) {
        ProcurePlan plan = procurePlanMapper.findByProcureId(procureId);
        return plan != null
                ? ResponseUtil.get(ResponseEnum.OK, plan)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil add(ProcurePlan procurePlan) {
        int rows = procurePlanMapper.add(procurePlan);
        return rows > 0
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil delete(String procureId) {
        int rows = procurePlanMapper.delete(procureId);
        return rows > 0
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil update(ProcurePlan procurePlan) {
        int rows = procurePlanMapper.update(procurePlan);
        return rows > 0
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil findByStatus() {
        List<ProcurePlan> list = procurePlanMapper.findByStatus();
        return !list.isEmpty()
                ? ResponseUtil.get(ResponseEnum.OK, list)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
    @Override
    public ResponseUtil findByCondition(ProcurePlan procurePlan) {
        List<ProcurePlan> list = procurePlanMapper.findByCondition(procurePlan);
        return !list.isEmpty()
                ? ResponseUtil.get(ResponseEnum.OK, list)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
}